home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / sql-bench / innotest2b < prev    next >
Encoding:
Text File  |  2003-01-22  |  3.2 KB  |  104 lines  |  [TEXT/ttxt]

  1. #!/usr/bin/perl
  2. ############################################################################
  3. #     Stress test for MySQL/Innobase combined database
  4. #     (c) 2000 Innobase Oy & MySQL AB
  5. #
  6. ############################################################################
  7.  
  8. use DBI;
  9. use Benchmark;
  10.  
  11. $opt_loop_count = 100000;
  12.  
  13. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  14. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  15.  
  16. print "Innotest2b: MySQL/InnoDB stress test in Perl for FOREIGN keys\n";
  17. print "------------------------------------------------------------\n";
  18. print "This is a randomized stress test for concurrent inserts,\n";
  19. print "updates, deletes, commits and rollbacks with foreign keys with\n";
  20. print "the ON DELETE ... clause. The test will generate\n";
  21. print "also a lot of deadlocks, duplicate key errors, and other SQL errors.\n";
  22. print "\n";
  23. print "You should run innotest2, innotest2a, and innotest2b concurrently.\n";
  24. print "The thing to watch is that the server does not crash or does not\n";
  25. print "print to the .err log anything. Currently, due to a buglet in MySQL,\n";
  26. print "warnings about MySQL lock reservations can appear in the .err log.\n";
  27. print "The test will run very long, even several hours. You can kill\n";
  28. print "the perl processes running this test at any time and do CHECK\n";
  29. print "TABLE on tables innotest2a, b, c, d in the 'test' database.\n";
  30. print "\n";
  31. print "Some of these stress tests will print a lot of SQL errors\n";
  32. print "to the standard output. That is not to be worried about.\n";
  33. print "You can direct the output to a file like this:\n";
  34. print "perl innotest2 > out2\n\n";
  35.  
  36. print "Generating random keys\n";
  37. $random[$opt_loop_count] = 0;
  38. $rnd_str[$opt_loop_count] = "a";
  39.  
  40. for ($i = 0; $i < $opt_loop_count; $i++) {
  41.  
  42.     $random[$i] = ($i * 98641) % $opt_loop_count;
  43.  
  44.       if (0 == ($random[$i] % 3)) {
  45.           $rnd_str[$i] = "khD";
  46.     } else { if (1 == ($random[$i] % 3)) {
  47.         $rnd_str[$i] = "khd";
  48.     } else { if (2 == ($random[$i] % 3)) {
  49.         $rnd_str[$i] = "kHd";
  50.     }}}
  51.  
  52.     for ($j = 0; $j < (($i * 764877) % 10); $j++) {
  53.         $rnd_str[$i] = $rnd_str[$i]."k";
  54.     }    
  55. }
  56.  
  57. ####
  58. ####  Connect
  59. ####
  60.  
  61. $dbh = $server->connect();
  62.  
  63. $dbh->do("set autocommit = 0");
  64.  
  65. for ($i = 0; $i < 1; $i++) {
  66.     print "loop $i\n";
  67.  
  68.     for ($j = 0; $j < $opt_loop_count - 10; $j = $j + 2) {
  69.         $dbh->do(
  70.         "insert into innotest2b (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
  71.         || print $dbh->errstr;
  72.  
  73.         $dbh->do(
  74.         "insert into innotest2a (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
  75.         || print $dbh->errstr;
  76.         
  77.         $dbh->do(
  78.         "insert into innotest2c (D, B, C) values (5, '".$rnd_str[$j]."' ,'".$rnd_str[$j]."')")
  79.         || print $dbh->errstr;
  80.  
  81.         $dbh->do("delete from innotest2b where A = ".$random[$random[$j]])
  82.         || print $dbh->errstr;
  83.  
  84.         $dbh->do("update innotest2b set A = A + 1 where A = ".$random[$j])
  85.         || print $dbh->errstr;
  86.  
  87.         if (0 == ($j % 10)) {
  88.             $dbh->do("commit");
  89.         }
  90.  
  91.         if (0 == ($j % 39)) {
  92.             $dbh->do("rollback");
  93.         }        
  94.  
  95.         if (0 == ($j % 1000)) {
  96.             print "round $j\n";
  97.         }
  98.     }    
  99.     
  100.     $dbh->do("commit");
  101. }                
  102.  
  103. $dbh->disconnect;                # close connection
  104.